﻿using XiaLastorm.Sharpshooter;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;

namespace TestProject1
{


	/// <summary>
	///这是 UserTest 的测试类，旨在
	///包含所有 UserTest 单元测试
	///</summary>
	[TestClass()]
	public class UserTest
	{


		private TestContext testContextInstance;

		/// <summary>
		///获取或设置测试上下文，上下文提供
		///有关当前测试运行及其功能的信息。
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}

		#region 附加测试特性
		// 
		//编写测试时，还可使用以下特性:
		//
		//使用 ClassInitialize 在运行类中的第一个测试前先运行代码
		//[ClassInitialize()]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//使用 ClassCleanup 在运行完类中的所有测试后再运行代码
		//[ClassCleanup()]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//使用 TestInitialize 在运行每个测试前先运行代码
		//[TestInitialize()]
		//public void MyTestInitialize()
		//{
		//}
		//
		//使用 TestCleanup 在运行完每个测试后运行代码
		//[TestCleanup()]
		//public void MyTestCleanup()
		//{
		//}
		//
		#endregion

		public readonly string[] LegalUsernameExamples;

		public UserTest()
		{
			LegalUsernameExamples = GetLegalUsernames();
		}

		public string[] GetLegalUsernames()
		{
			string[] usernames = new string[100];
			int count = 0;
			for (int i = 0; i < usernames.Length; ++i)
			{
				int length = i % 20 + 1;
				StringBuilder sb = new StringBuilder(length);
				for (int j = 0; j < length; ++j)
				{
					sb.Append(User.LegalCharsOfUsername[count]);
					++count;
					if (count >= User.LegalCharsOfUsername.Length)
						count = 0;
				}
				usernames[i] = sb.ToString();
			}
			return usernames;
		}

		/// <summary>
		///User 构造函数 的测试
		///</summary>
		[TestMethod()]
		public void UserConstructorTest()
		{
			foreach (var username in LegalUsernameExamples)
			{
				User target = new User(username);
				Assert.AreEqual(target.Username, username);
			}
		}

		/// <summary>
		///User 构造函数 的测试
		///</summary>
		[TestMethod()]
		[ExpectedException(typeof(ArgumentNullException))]
		public void UserConstructorTestArgumentNullException()
		{
			string username = null;
			User target = new User(username);
		}

		/// <summary>
		///User 构造函数 的测试
		///</summary>
		[TestMethod()]
		[ExpectedException(typeof(ArgumentException))]
		public void UserConstructorTestArgumentException()
		{
			string username = string.Empty;
			User target = new User(username);
		}
		/// <summary>
		///User 构造函数 的测试
		///</summary>
		[TestMethod()]
		[ExpectedException(typeof(ArgumentException))]
		public void UserConstructorTestArgumentException1()
		{
			string username = new string(' ', 5);
			User target = new User(username);
		}
		/// <summary>
		///User 构造函数 的测试
		///</summary>
		[TestMethod()]
		[ExpectedException(typeof(ArgumentException))]
		public void UserConstructorTestArgumentException2()
		{
			string username = "\t\b";
			User target = new User(username);
		}
		/// <summary>
		///User 构造函数 的测试
		///</summary>
		[TestMethod()]
		[ExpectedException(typeof(ArgumentException))]
		public void UserConstructorTestArgumentException3()
		{
			string username = "\n";
			User target = new User(username);
		}

		/// <summary>
		///Equals 的测试
		///</summary>
		[TestMethod()]
		public void EqualsTest()
		{
			{
				string username = "NewUser";
				User target = new User(username);
				object obj = null;
				bool expected = false;
				bool actual;
				actual = target.Equals(obj);
				Assert.AreEqual(expected, actual);
			}

			for (int i = 0; i < LegalUsernameExamples.Length; ++i)
				for (int j = i; j < LegalUsernameExamples.Length; ++j)
				{
					User target = new User(LegalUsernameExamples[i]);
					object obj = new User(LegalUsernameExamples[j]);
					bool expected = LegalUsernameExamples[i] == LegalUsernameExamples[j];
					bool actual = target.Equals(obj);
					Assert.AreEqual(expected, actual);
				}
		}

		/// <summary>
		///Equals 的测试
		///</summary>
		[TestMethod()]
		public void EqualsTest1()
		{
			{
				string username = "NewUser";
				User target = new User(username);
				User other = null;
				bool expected = false;
				bool actual;
				actual = target.Equals(other);
				Assert.AreEqual(expected, actual);
			}

			for (int i = 0; i < LegalUsernameExamples.Length; ++i)
				for (int j = i; j < LegalUsernameExamples.Length; ++j)
				{
					User target = new User(LegalUsernameExamples[i]);
					User other = new User(LegalUsernameExamples[j]);
					bool expected = LegalUsernameExamples[i] == LegalUsernameExamples[j];
					bool actual = target.Equals(other);
					Assert.AreEqual(expected, actual);
				}
		}

		/// <summary>
		///GetHashCode 的测试
		///</summary>
		[TestMethod()]
		public void GetHashCodeTest()
		{
			foreach (var username in LegalUsernameExamples)
			{
				User target = new User(username);
				int expected = username.GetHashCode();
				int actual;
				actual = target.GetHashCode();
				Assert.AreEqual(expected, actual);
			}
		}

		/// <summary>
		///ToString 的测试
		///</summary>
		[TestMethod()]
		public void ToStringTest()
		{
			foreach (var username in LegalUsernameExamples)
			{
				User target = new User(username);
				string expected = username;
				string actual;
				actual = target.ToString();
				Assert.AreEqual(expected, actual);
			}
		}

		/// <summary>
		///Information 的测试
		///</summary>
		[TestMethod()]
		public void InformationTest()
		{
			string username = "NewUser";
			User target = new User(username);
			UserInformation expected = null;
			UserInformation actual;
			target.Information = expected;
			actual = target.Information;
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///Nickname 的测试
		///</summary>
		[TestMethod()]
		public void NicknameTest()
		{
			string username = "NewUser";
			User target = new User(username);
			string expected = string.Empty;
			string actual;
			target.Nickname = expected;
			actual = target.Nickname;
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///Password 的测试
		///</summary>
		[TestMethod()]
		public void PasswordTest()
		{
			string username = "NewUser";
			User target = new User(username);
			string expected = string.Empty;
			string actual;
			target.Password = expected;
			actual = target.Password;
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///Username 的测试
		///</summary>
		[TestMethod()]
		public void UsernameTest()
		{
			foreach (var username in LegalUsernameExamples)
			{
				User target = new User(username);
				string expected = username;
				string actual;
				target.Username = expected;
				actual = target.Username;
				Assert.AreEqual(expected, actual);
			}
		}
	}
}
